import 'package:course_control/app/routes/app_pages.dart';
import 'package:course_control/config/app.dart';
import 'package:flutter/material.dart';

import 'package:get/get.dart';
import '../../../../gen/assets.gen.dart';
import '../controllers/splash_controller.dart';
import 'package:easy_splash_screen/easy_splash_screen.dart';

class SplashView extends GetView<SplashController> {
  const SplashView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return const _SplashPage();
  }
}

class _SplashPage extends StatefulWidget {
  const _SplashPage({Key? key}) : super(key: key);
  @override
  _SplashPageState createState() => _SplashPageState();
}

class _SplashPageState extends State<_SplashPage> {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      Get.offAllNamed(Routes.START);
    });
  }

  @override
  Widget build(BuildContext context) {
    return EasySplashScreen(
      logo: Image.asset(Assets.images.splash.path),
      title: const Text(
        appName,
        style: TextStyle(
          fontSize: 18,
          fontWeight: FontWeight.bold,
        ),
      ),
      backgroundColor: Colors.grey.shade400,
      showLoader: true,
      loadingText: const Text("Loading..."),
    );
  }
}
